package com.guocheng.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guocheng.Utils.MapStruct.GoodInfoStruct;
import com.guocheng.mapper.GoodInfoMapper;
import com.guocheng.mapper.GoodTypeMapper;
import com.guocheng.model.dto.GoodInfoDto;
import com.guocheng.model.po.GoodInfo;
import com.guocheng.model.po.GoodType;
import com.guocheng.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GoodServiceImpl implements GoodService {
    @Autowired
    private GoodInfoStruct goodInfoStruct;
    @Autowired
    private GoodInfoMapper goodInfoMapper;
    @Autowired
    private GoodTypeMapper goodTypeMapper;

    public GoodInfoDto findGoodInfo(Integer id){
        if (id == null){
            return null;

        }
        GoodInfo goodInfo = goodInfoMapper.selectOne(new QueryWrapper<GoodInfo>().eq("tg_id", id));
        GoodType goodType = goodTypeMapper.selectOne(new QueryWrapper<GoodType>().eq("tgt_id", goodInfo.getTypeId()));
        return goodInfoStruct.from(goodInfo,goodType);
    }
}
